//
//  MyGameScene.cpp
//  CanYouDoIt
//
//  Created by hoangtx on 7/13/13.
//
//

#include "MyGameScene.h"
#include "StaticVariables.h"
#include "SceneManager.h"
void MyGameScene::startGame(){
    setTouchEnabled(true);
    scoreAndTimeLayer->setVisible(true);
    this->schedule(schedule_selector(MyGameScene::onTick), 1);
}

void MyGameScene::reset(){
    
    setTouchEnabled(false);
    scoreAndTimeLayer->setVisible(true);
    failLabel->setVisible(false);
}

void MyGameScene::gameOver(){
    setTouchEnabled(false);
    this->unscheduleAllSelectors();
    this->unscheduleUpdate();
    failLabel->setVisible(true);
    this->schedule(schedule_selector(MyGameScene::didShowingFailMessage), 1, 0, 0);
}

void MyGameScene::getReady(){
    countDownLayer->getReady();
}

void MyGameScene::didShowingFailMessage(float dt){
    CCTransitionFlipX* transition = CCTransitionFlipX::create(0.5f, SceneManager::sharedInstance()->resultScene, kCCTransitionOrientationLeftOver);
    CCDirector::sharedDirector()->replaceScene(transition);
}

void MyGameScene::onTick(float dt){
    
}

bool MyGameScene::init(){

    scoreAndTimeLayer = ScoreAndTimeLayer::create();
    
    this->addChild(scoreAndTimeLayer,2);
    scoreAndTimeLayer->setVisible(true);
    
    setTouchEnabled(false);
    countDownLayer = ReadyCountDownLayer::create();
    countDownLayer->scene = this;
    countDownLayer->countDownLabel->setPosition(ccp(countDownLayer->countDownLabel->getPositionX(),countDownLayer->countDownLabel->getPositionY()-scoreAndTimeLayer->getBarHeight()/2));
    this->addChild(countDownLayer,2);
    
    
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    failLabel = CCLabelBMFont::create("Fail!", "Info.fnt");
    failLabel->setAnchorPoint(ccp(0.5,0.5));
    failLabel->setPosition(ccp(winSize.width/2,(winSize.height - scoreAndTimeLayer->getBarHeight())/2));
    failLabel->setScale(winSize.height*0.1/failLabel->getContentSize().height);
    failLabel->setVisible(false);
    this->addChild(failLabel,3);
    return true;
}
